/**
 * 
 */
package info.niwota.fwrite;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ListView;

/**
 * @author qiangli
 *
 */
public class IncomingMessageActivity extends ListActivity {

	private static final String TAG = "IncomingMessageActivity";
	
	public static final String SESSION_INFO = SessionListActivity.SESSION_INFO;
	
	private SessionListAdapter adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
	    if (Debug.DEBUG) {
			Log.d(TAG, "onCreate: " + savedInstanceState);
		}
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_LEFT_ICON);
		setContentView(R.layout.sess_list);
	
		adapter = new SessionListAdapter(this, SessionManager.listIncomingMessages());
		//
		final ListView lv = getListView();
		lv.setAdapter(adapter);
		lv.setItemsCanFocus(true);
		lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
		//
		registerForContextMenu(lv);
		
		setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.frite22);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int pos, long id) {
		SessionInfo si = adapter.getItem(pos);
		Preferences.putPeer(this, si.peer);
		
		Intent intent = new Intent(this, WriteActivity.class);
		startActivity(intent);
		finish();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}
}
